/*
 * Copyright (c) 2009, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "sys/queue.h"
#include "tssp.h"
#include "tssp_table.h"

#ifndef _TSSP_DVB_SDT_H_
#define _TSSP_DVB_SDT_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

struct tssp_dvb_sdt_service {
    uint16_t service_id;    /**< service_id */
    uint8_t eit_schedule;   /**< EIT_schedule_flag */
    uint8_t eit_present;    /**< EIT_present_following_flag */
    uint8_t running_status; /**< running_status */
    uint8_t free_ca_mode;   /**< free_CA_mode */
    struct tssp_descriptors descriptors;

    STAILQ_ENTRY(tssp_dvb_sdt_service) entry; /**< Only for internal use, do not access. */
};

STAILQ_HEAD(tssp_dvb_sdt_services, tssp_dvb_sdt_service);

struct tssp_dvb_sdt {
    uint16_t ts_id;         /**< transport_stream_id */
    uint8_t version;        /**< version_number */
    uint8_t current_next;   /**< current_next_indicator */
    uint16_t network_id;    /**< original_network_id */

    struct tssp_dvb_sdt_services services; /**< service loop */
};

struct tssp_dvb_sdt_monitor;

typedef
void (*tssp_dvb_sdt_monitor_callback)(struct tssp_dvb_sdt_monitor *monitor,
                                      struct tssp_dvb_sdt *sdt,
                                      struct tssp_section *section,
                                      void *userdata);

struct tssp_dvb_sdt *tssp_dvb_sdt_parse(const struct tssp_section *section);
struct tssp_dvb_sdt *tssp_dvb_sdt_create();
void tssp_dvb_sdt_destroy(struct tssp_dvb_sdt *sdt);
struct tssp_dvb_sdt_service *
tssp_dvb_sdt_add_service(struct tssp_dvb_sdt *sdt,
                         uint16_t service_id,
                         uint8_t eit_schedule,
                         uint8_t eit_present,
                         uint8_t running_status,
                         uint8_t free_ca_mode);

void tssp_dvb_sdt_service_destroy(struct tssp_dvb_sdt_service *sdt_service);

struct tssp_dvb_sdt_monitor *
tssp_dvb_sdt_monitor_attach(struct tssp *parser,
                            uint16_t ts_id,
                            uint8_t current_next,
                            tssp_dvb_sdt_monitor_callback callback,
                            void *userdata);
void tssp_dvb_sdt_monitor_detach(struct tssp_dvb_sdt_monitor *monitor);
void tssp_dvb_sdt_monitor_reset(struct tssp_dvb_sdt_monitor *monitor);

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif /* _TSSP_DVB_SDT_H_ */

